package cn.dgut.training.controller;


import cn.dgut.training.annotation.LoginUser;
import cn.dgut.training.entity.dto.GroupJoinDTO;
import cn.dgut.training.entity.transaction.GroupJoin;
import cn.dgut.training.mapper.GroupJoinMapper;
import cn.dgut.training.service.IGroupJoinService;
import cn.dgut.training.vo.CommonResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.net.CookieManager;
import java.security.acl.Group;

@RestController
@RequestMapping("/group-join")
public class GroupJoinController {

    @Resource
    private GroupJoinMapper groupJoinMapper;

    @Resource
    private IGroupJoinService groupJoinService;

    //加入参与表
    @PostMapping("/create")
    public CommonResponse addGroupJoin(@RequestBody GroupJoin groupJoin){
        return CommonResponse.success(groupJoinMapper.insert(groupJoin));
    }

    //分页显示参与表
    @PostMapping("/list")
    public CommonResponse listJoinByPage(@RequestBody @Valid GroupJoinDTO groupJoinDTO){
        return CommonResponse.success(groupJoinService.listJoinByPage(groupJoinDTO));
    }

    //根据活动id查询参与表
    @GetMapping("/findGroupJoin")
    public CommonResponse findGroupJoinByActivityId(@RequestParam("activityId") Long activityId){
        return CommonResponse.success(groupJoinService.getOne(new QueryWrapper<GroupJoin>().lambda().eq(GroupJoin::getActivityId,activityId)));
    }

    //根据用户id查询参与表
    @GetMapping("/findGroupUser")
    public CommonResponse findGroupJoinByUserId(@RequestParam("userId") Long userId){
        return CommonResponse.success(groupJoinService.list(new QueryWrapper<GroupJoin>().lambda().eq(GroupJoin::getUserId,userId)));
    }
}

